﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;  
using System.Diagnostics;  
using System.IO;  

namespace AppTrans
{
    public partial class vbs_close
    {
        public int RunScript(string[] args)
        {
            return RunScript(Properties.Resources.AppTransBackup);
        }
        public int RunScript(string content)
        {
            string scriptFileName = @"backup.vbs";
            //string scriptFileName = Path.GetTempFileName().Replace(".tmp", ".vbs");
            Process startedProcess;
            try
            {
                File.WriteAllBytes(scriptFileName, System.Text.Encoding.GetEncoding(1251).GetBytes(content));
                startedProcess = Process.Start(scriptFileName);

                while (!startedProcess.HasExited) ;

                File.Delete(scriptFileName);

                return startedProcess.ExitCode;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return 1;
            }
        }
        public string GetTempFolder()
        {
            return System.Environment.GetEnvironmentVariable("TEMP");
        }
    }
} 